<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!--1.引入 bootstrap 框架全局样式 -->
    <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css"/>
    <!--2.引入 angularJS 分页的样式 -->
    <link rel="stylesheet" href="../angularjs/pagination.css">
    <!--3.引入 jquery 框架类库 -->
    <script src="../bootstrap/js/jquery.min.js"></script>
    <!--4.引入 bootstrap 框架类库 -->
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <!--5.引入 angularJS 框架类库 -->
    <script src="../angularjs/angular.min.js"></script>
    <!--6.引入 angularJS 框架分页的类库 -->
    <script src="../angularjs/pagination.js"></script>
    <!--7.引入layer css-->
    <link rel="stylesheet" href="https://www.layuicdn.com/layui/css/layui.css">
    <!--8.引入layer js-->
    <script src="https://www.layuicdn.com/layui/layui.js"></script>
    <script>
        var app = angular.module("myApp", ['ngCookies']).config(function ($httpProvider) {
            $httpProvider.defaults.useXDomain = true;
            delete $httpProvider.defaults.headers
                .common['X-Requested-With']
        });
        app.controller("UserController", function ($scope, $http, $window, $cookieStore) {
            $scope.login = function () {
                console.log($scope.user);
                $http.post("http://localhost:10088/admin/login", $scope.user).success(function (data) {
                    if (data.code === 200) {
                        layer.msg("登录成功");
                        console.log(data);
                        $window.localStorage.setItem("tokens",data.token);
                        //拥有admin进入下面的页面
                        if (data.data.rname==="admin"){
                            $window.localStorage.setItem("rname",data.data.rname);
                            $window.location.href = "UserList.html";
                        }
                        //拥有inspector进入下面页面
                        if (data.data.rname==="inspector"){
                            $window.localStorage.setItem("rname",data.data.rname);
                            $window.location.href = "../inspector/index.html";
                        }
                        //拥有manager进入下面页面
                        if (data.data.rname==="manager"){
                            $window.localStorage.setItem("rname",data.data.rname);
                            $window.location.href = "../manager/index.html";
                        }
                        //拥有distribution进入下面页面
                        if (data.data.rname==="distribution"){
                            $window.localStorage.setItem("rname",data.data.rname);
                            $window.location.href = "../distribution/index.html";
                        }

                    } else {
                        layer.msg("登录失败,密码账号错误或者没有访问权限");
                    }
                });
            };
        })
    </script>
    <script src="../angularjs/angular.min.js"></script>
    <script src="../angularjs/angular-animate.min.js"></script>
    <script src="../angularjs/angular-route.min.js"></script>
</head>

<body ng-app="myApp" ng-controller="UserController"
      style=" background: url(http://global.bing.com/az/hprichbg/rb/RavenWolf_EN-US4433795745_1920x1080.jpg) no-repeat center center fixed; background-size: 100%;">
<div class="modal-dialog" style="margin-top: 10%;">
    <div class="modal-content">
        <div class="modal-header">

            <h4 class="modal-title text-center" id="myModalLabel">后台管理系统登录</h4>
        </div>
        <form role="form">
            <div class="modal-body " id="model-body">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="手机号或者邮箱" autocomplete="off"
                           ng-model="user.phone">
                </div>
                <div class="form-group">
                    <input type="password" class="form-control" placeholder="密码" autocomplete="off"
                           ng-model="user.password">
                </div>
            </div>
            <div class="modal-footer">
                <div class="form-group">
                    <button type="button" class="btn btn-primary form-control" value="登陆" ng-click="login()">登陆</button>

                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>
